<!DOCTYPE html>
<html>
<head>
    <title>GraphQL Test</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 40px 20px;
            background: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 30px;
            text-align: center;
        }
        .input-group {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        input {
            flex: 1;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
        }
        input:focus {
            outline: none;
            border-color: #007bff;
        }
        button {
            padding: 12px 24px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
        }
        button:hover {
            background: #0056b3;
        }
        #result {
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 20px;
            min-height: 100px;
            max-height: 400px;
            overflow-y: auto;
            font-family: inherit;
            white-space: pre-wrap;
            line-height: 1.6;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🤖 AI Chat using GraphQL API & Websockets</h1>
        <div class="input-group">
            <input type="text" id="input" placeholder="Ask me anything...">
            <button onclick="testAPI()">Send</button>
        </div>
        <div id="result">Ready to chat! Enter your message above.</div>
    </div>

    <script>
        const API_URL = '<GraphQLAPIURL>'; // Replace with your GraphQL URL / HTTP Endpoint
        const API_KEY = '<GraphQLAPIKey>';     // Replace with your API Key

        async function testAPI() {
            const input = document.getElementById('input').value;
            const mutation = {
                query: `mutation { invokeModel(input: "${input}") }`
            };

            try {
                const response = await fetch(API_URL, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'x-api-key': API_KEY
                    },
                    body: JSON.stringify(mutation)
                });

                const result = await response.json();
                const responseText = result.data?.invokeModel || 'No response';
                document.getElementById('result').textContent = responseText;
            } catch (error) {
                document.getElementById('result').innerHTML = 'Error: ' + error.message;
            }
        }
    </script>
</body>
</html>